package com.yuzhi.master.drainagePermit.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuzhi.common.core.page.PageDataInfo;
import com.yuzhi.master.drainagePermit.domain.DrainDrainagePermit;
import com.yuzhi.master.drainagePermit.domain.bo.DrainDrainagePermitBo;
import com.yuzhi.master.drainagePermit.domain.request.DrainDrainagePermitReq;
import com.yuzhi.master.drainagePermit.domain.vo.DrainDrainagePermitView;
import com.yuzhi.master.drainagePermit.domain.vo.DrainDrainagePermitVo;
import com.yuzhi.master.drainagePermit.mapper.DrainDrainagePermitMapper;
import com.yuzhi.master.drainagePermit.mapper.DrainDrainagePermitViewMapper;
import com.yuzhi.master.drainagePermit.service.IDrainDrainagePermitService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 排水许可证Service业务层处理
 *
 * @author coding123
 * @date 2025-07-15
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class DrainDrainagePermitServiceImpl extends ServiceImpl<DrainDrainagePermitMapper, DrainDrainagePermit> implements IDrainDrainagePermitService {

    private final DrainDrainagePermitMapper baseMapper;
    private final DrainDrainagePermitViewMapper viewMapper;

    /**
     * 查询排水许可证
     */
    @Override
    public DrainDrainagePermitVo queryById(String id) {
        return baseMapper.selectVoById(id);
    }

    /**
     * 查询排水许可证列表
     */
    @Override
    public PageDataInfo<DrainDrainagePermitVo> queryPageList(DrainDrainagePermitReq request) {
        LambdaQueryWrapper<DrainDrainagePermit> lqw = buildQueryWrapper(request);
        Page<DrainDrainagePermitVo> result = baseMapper.selectVoPage(request.getPageQuery().build(), lqw);
        return PageDataInfo.build(result);
    }

    /**
     * 分页查询排水许可证列表
     */
    @Override
    public PageDataInfo<DrainDrainagePermitView> queryPageViewList(DrainDrainagePermitReq req) {

        return PageDataInfo.build();
    }


    /**
     * 查询排水许可证列表
     */
    @Override
    public List<DrainDrainagePermitVo> queryList(DrainDrainagePermitReq request) {
        LambdaQueryWrapper<DrainDrainagePermit> lqw = buildQueryWrapper(request);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<DrainDrainagePermit> buildQueryWrapper(DrainDrainagePermitReq request) {
        Map<String, Object> params = request.getParams();
        LambdaQueryWrapper<DrainDrainagePermit> lqw = Wrappers.lambdaQuery();
        return lqw;
    }

    /**
     * 新增排水许可证
     */
    @Override
    public Boolean insertByBo(DrainDrainagePermitBo bo) {

        return true;
    }

    /**
     * 修改排水许可证
     */
    @Override
    public Boolean updateByBo(DrainDrainagePermitBo bo) {
        return true;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(DrainDrainagePermit entity) {
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除排水许可证
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<String> ids, Boolean isValid) {
        if (isValid) {
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }

    /**
     * 根据id删除排水许可证信息
     */
    @Override
    public Boolean deleteById(String id, Boolean isValid) {
        if (isValid) {
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteById(id) > 0;
    }


    /**
     * 查询排水许可证
     */
    @Override
    public DrainDrainagePermitView getInfoViewById(String id) {
        return null;
    }


}
